<%- scope[:stage_details_action] ||= params[:action] -%>
<div id="stage_bar_<%= scope[:idx_in_status_bar] %>" class="row1">
    <% if placeholder_stage?(scope[:stage_in_status_bar]) %>
        <span class="stage_name"><%= scope[:stage_name] -%></span>
    <% else %>
        <%= link_to scope[:stage_in_status_bar].getName(), stage_bar_url(scope[:stage_in_status_bar], scope[:stage_details_action]), :class=> "stage_name" %>
    <% end %>

    <% if scope[:stage_in_status_bar].hasOperatePermission() %>
        <%

           if scope[:stage_in_status_bar].isRunning()
               scope[:label] = "cancel"
           elsif scope[:stage_in_status_bar].canRun()
               scope[:label] = run_stage_label(scope[:stage_in_status_bar])
           end

           scope[:operate_class] = "action_#{scope[:label]}"
        %>
        <div id="operate_<%= scope[:stage_name] %>" class="operate secondary <%= scope[:operate_class] %>">
            <%
               scope[:id] = "stage_bar_#{scope[:label]}_#{scope[:stage_name]}"
               scope[:title] = "#{scope[:label]} #{scope[:stage_name]}"
               scope[:html_opts] = {:class => "stage_action", :id => scope[:id], :title => scope[:title], :'aria-label' => scope[:title]}
               scope[:idForSpinner] = "operate_#{scope[:stage_name]}"
               if scope[:stage_in_status_bar].canRun() && scope[:stage_in_status_bar].isScheduled() %>
                <%== link_blocking_post_to_server :name => "&nbsp;",
                                                  :html => scope[:html_opts],
                                                  :url => run_stage_path(:stage_name => scope[:stage_name], stage_counter: scope[:stage_counter]),
                                                  :idForSpinner => scope[:idForSpinner] %>

                <% end %>
                <% if scope[:stage_in_status_bar].isRunning() %>
                    <%== link_blocking_post_to_server :name => "&nbsp;",
                                                      :html => scope[:html_opts],
                                                      :url => cancel_stage_path(@pipeline),
                                                      :idForSpinner => scope[:idForSpinner] %>
                <% end %>
        </div>
    <% end %>
</div>
<% scope[:stage_bar_html_options] = stage_bar_options(scope[:stage_in_status_bar]) %>
<div class="stage_bar_wrapper">
    <% if placeholder_stage?(scope[:stage_in_status_bar]) %>
        <div <%= scope[:stage_bar_html_options] -%>></div>
    <% else %>
        <a href="<%= stage_bar_url(scope[:stage_in_status_bar], scope[:stage_details_action]) -%>" <%= scope[:stage_bar_html_options] -%>></a>
    <% end %>
</div>
<% if scope[:idx_in_status_bar] > 0 %>
    <div class="trigger_gate">
        <%= render :partial => "pipelines/stage_trigger_gate", :locals => {:scope => {:stage_in_status_bar => scope[:stage_in_status_bar]}} %>
    </div>
<% end %>
